import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusPackage/provider/package_detail_provider.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/radioList/checkbox.dart';
import 'package:boss/ui/widget/timeRangePicker/time_range_picker.dart';
import 'package:hi_common/hi_common.dart';
import 'package:boss/util/time_util.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package_panel.dart';
import 'toggle_btn_group.dart';

class SellPanel extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer<PackageDetailProvider>(
      builder: (context, provider, _) {
        return PackagePanel(
          title: '售卖设置',
          children: <Widget>[
            ToggleBtnGroup(
              btns: ['全周', '工作日', '周末', '自定义'],
              selectedIndex: provider.sellDayIndex,
              spacing: 20.w,
              margin: EdgeInsets.only(
                bottom: 30.w,
              ),
              onChanged: (value) {
                if (value == 0) {
                  provider.setSellDay([0, 1, 2, 3, 4, 5, 6]);
                } else if (value == 1) {
                  provider.setSellDay([0, 1, 2, 3, 4]);
                } else if (value == 2) {
                  provider.setSellDay([5, 6]);
                }
              },
            ),
            CheckBox<int>(
              items: [
                CheckBoxData(title: '周一', value: 0),
                CheckBoxData(title: '周二', value: 1),
                CheckBoxData(title: '周三', value: 2),
                CheckBoxData(title: '周四', value: 3),
                CheckBoxData(title: '周五', value: 4),
                CheckBoxData(title: '周六', value: 5),
                CheckBoxData(title: '周日', value: 6),
              ],
              value: provider.sellDays,
              onChanged: (value) {
                provider.setSellDay(value);
              },
            ),
            Container(
              child: CustomDivider(),
              margin: EdgeInsets.symmetric(
                vertical: 30.w,
              ),
            ),
            ToggleBtnGroup(
              btns: ['全天', '午市', '晚市', '自定义'],
              selectedIndex: provider.sellTimeIndex,
              spacing: 20.w,
              margin: EdgeInsets.only(
                bottom: 30.w,
              ),
              onChanged: (value) async {
                if (value == 0) {
                  provider.setSellTime('00:00-23:59');
                } else if (value == 1) {
                  provider.setSellTime('10:00-14:00');
                } else if (value == 2) {
                  provider.setSellTime('17:00-23:00');
                } else {
                  var res = await showTimeRangePicker(context);
                  if (res != null) {
                    provider.setSellTime(TimeUtil.timeArr2String(res));
                  }
                }
              },
            ),
            Container(
              child: Text(
                '已选时间${provider.sellStartTimeText}至${provider.sellEndTimeText}',
                style: TextStyleConstant().normal_1_22,
              ),
            ),
            ToggleBtnGroup(
              btns: packageTags.map((item) => item.tag).toList(),
              selectedIndex: provider.package.packagesTag,
              spacing: 20.w,
              margin: EdgeInsets.symmetric(
                vertical: 30.w,
              ),
              onChanged: (index) {
                provider.setPackageTag(index);
              },
            ),
          ],
        );
      },
    );
  }
}
